﻿/**
* Vista asociada al contenido 
* con la interfaz que muestra con perfil de usurio tipo 1(Ver Proyecto)
* en el aplicativo.
*/
Ext.define("entgpv11.view.MenuUser01", {
    extend: "Ext.form.Panel",
    requires: "Ext.form.FieldSet",
    alias: "widget.menuuser01",
    config: {
        scrollable: 'vertical',
		dataId:0,
		rol:'ADM'
    },
	requires: [
       	'entgpv11.view.ContentMenu01.NotesContainer'
    ],
    initialize: function () {
      try
      {
        this.callParent(arguments);
	    var valueHidden = this.getDataId();
	    var exitButton = {
            xtype: "button",
            ui: 'decline',
            iconCls: "delete",iconMask: true,
            handler: this.onBackButtonTap,
            scope: this
        };
		var backButton = {
            xtype: "button",
            ui: "back",
           iconCls: "reply",iconMask: true,
            handler: this.onBackButtonTap,
            scope: this
        };		
        var topToolbar = {
            xtype: "toolbar",
            docked: "top",
            title: "",
            items: [
                backButton,
                { xtype: "spacer" },
                exitButton
            ]
        };
        var bottomToolbar = {
            xtype: "toolbar",
            docked: "bottom",
            items: [
                
            ]
        };
		var lblInfo ={
			xtype: 'fieldset',
			title: 'Proyectos',
			instructions: 'Seleccione criterios para realizar la busqueda de proyectos',
		};
		var storeList01 = Ext.create("entgpv11.store.Filter");
		//selectPrograma
		APP_GLOBAL.SetProxyExtraParams(storeList01,{iCriterio:"2",idImpresa:valueHidden});
		// loading mask for this Store
		var mask =new Ext.LoadMask(Ext.getBody(),{msg:'Cargando datos...', store: storeList01});
		storeList01.load();
    	mask.show();
        var n = storeList01.getCount();
        var selectPrograma = {
                xtype: 'textfield',
                name: 'iProgramaId',
                hidden: true,
                value: 0
        };
        if (n != 0) {
            selectPrograma = {
			    xtype: "selectfield",
			    label: "Programa",
			    name: "iProgramaId",
			    store: storeList01,
			    displayField:"Value",
			    valueField:"Key"
		    };
        }
		//selectEje
		var storeList02 = Ext.create("entgpv11.store.Filter");
		APP_GLOBAL.SetProxyExtraParams(storeList02,{iCriterio:"1",idImpresa:valueHidden});
		storeList02.load();
		n = storeList02.getCount();
        var selectEje = {
                xtype: 'textfield',
                name: 'iEjeId',
                hidden: true,
                value: 0
        };
        if (n == 0) {
            selectEje = {
			    xtype: "selectfield",
			    label: "Eje",
			    name: "iEjeId",
			    store: storeList02,
			    displayField:"Value",
			    valueField:"Key"
		    };
        }
		//selectTipo
		//var storeList03 =Ext.create("entgpv11.store.Filter");
		//APP_GLOBAL.SetProxyExtraParams(storeList03,{iCriterio:"3",idImpresa:"0"});
		//storeList03.load();
		/*
		var selectTipo = {
			xtype: "selectfield",
			label: "Tipo",
			name: "iTipoId",
			store: storeList03,
			displayField:"Value",
			valueField:"Key"
		};
		*/
		var selectTipo = {
            xtype: 'textfield',
            name: 'iTipoId',
			hidden:true,
            value: '0' 
        };
		//selectEstado
		var storeList04 = Ext.create("entgpv11.store.Filter");
		APP_GLOBAL.SetProxyExtraParams(storeList04,{iCriterio:"4",idImpresa:"0"});
		storeList04.load();
	    n = storeList04.getCount();
        var selectEstado = {
                xtype: 'textfield',
                name: 'iEstadoId',
                hidden: true,
                value: 0
        };
        if (n != 0) {
		     selectEstado = {
			    xtype: "selectfield",
			    label: "Estado",
			    name: "iEstadoId",
			    store: storeList04,
			    displayField:"Value",
			    valueField:"Key"
		    };
        }
		//
		var txtNombre = {
            xtype: 'searchfield',
            name: 'sText',
            label: 'Nombre'
        };
		var hidEmp = {
            xtype: 'textfield',
            name: 'IdEmp',
			hidden:true,
            value: valueHidden 
        };
		var btnSeek = {
            xtype: "button",
            text: 'Buscar',
            ui: 'action',
            handler: this.onBtnSeek,
            scope: this
        };
		if (this.getRol()=="ADM")
		{
			this.add([
				topToolbar,
				lblInfo,
				{ xtype: "fieldset",
					items: [
							selectPrograma,
							selectEje,
							selectTipo,
							selectEstado,
							txtNombre,
							hidEmp,
							{ xtype: "spacer" },
							btnSeek
					]
				},
				{ xtype: "spacer" },
				bottomToolbar
			]);
		}
		else
		{
			this.add([
			         lblInfo,
					{ xtype: "fieldset",
						items: [
								selectPrograma,
								selectEje,
								selectTipo,
								selectEstado,
								txtNombre,
								hidEmp,
								{ xtype: "spacer" },
								btnSeek
						]
					}
			]);
		
		}
		 mask.hide( );
        } catch (ex) {
            APP_GLOBAL.SetLog('MenuUser01.initialize::' + ex);
        }
    },
	onBackButtonTap: function () {
        //console.log("backButtonTap");
        this.fireEvent("backButtonTapCommand", this);
    },
	onBtnSeek: function () {
        //console.log("onBtnSeek");
        this.fireEvent("btnSeekCommand", this);
    }
   
});

